import sqlite3

from flask import Blueprint, request, g, current_app

database_name = "userdata.db"  # 使用记录数据库
api_blueprint = Blueprint("api_db_blueprint", __name__)


def get_db():
    db = getattr(g, '_database', None)
    if db is None:
        db = g._database = sqlite3.connect(database_name)
    return db


@api_blueprint.route("/insertrevise")
def insertrevise():
    question = request.args.get("question")
    answer = request.args.get("answer")
    context = request.args.get("context")
    revise = request.args.get("revise")

    cur = get_db().cursor()
    cur.execute("INSERT INTO revise VALUES (?, ?, ?, ?)", (question, answer, context, revise))
    get_db().commit()
    return
